//智能指针的其他用法
//需要注意的是，智能指针是ownership  不是单单用于自动内存管理
    void ptr_test(){

        int file = 7;
        auto fd_closer = [=](int fd){ close(fd) ; };
        unique_ptr<int, decltype(fd_closer)> guard{&file, fd_closer};
        
    }






// My Vector

template <typename T >
struct identity{
    typedef T  type;
};

template<typename T>
struct VectorSized{


    template<typename N>
    void fills(){
        fill_detail( identity<N>());
    }

    template<typename  N>
    void fill_detail( identity<N>){
    }

    void fill_detail( identity<int>){
        fill(data.begin(), data.end(), 0);
    }

    void fill_detail( identity<double>){
        fill(data.begin(), data.end(), 0);
    }

    void fill_detail (identity<BuffUnit>){
        BuffUnit zero;
        memset(&zero, 0 , sizeof(zero) );
        fill(data.begin(), data.end(),zero );
    }

    vector<T> data;
    string ticker;
    size_t write_idx;
    size_t read_idx;
    int size;
    VectorSized(const int &p_size = 0){
        write_idx = 0;
        read_idx = 0;
        size = p_size == 0 ? VECTOR_SIZED : p_size;
        data.resize(size);
      //  fun<T>();
         //fills(data.begin(), data.end(), 0);
         fills<T>();
/*
        if (is_same<T, double>::value ){

            fill(data.begin(), data.end(), 0);
        }

        else if (is_same<T, int>::value ){
            fill(data.begin(), data.end(), 0);
        }

        else if (is_same<T, BuffUnit>::value){
            BuffUnit zero;
            memset(&zero, 0 , sizeof(zero) );
            fill(data.begin(), data.end(),zero );

        }
        /*
        else {
            cout<<"exception type  init struct VectorSized" <<endl;
        }
         */
    }


    void push(const T & t ){
            if(write_idx < size){
                data[write_idx++] = t;
            }
            else{
                realloc();
                data[write_idx++] = t;
            }
    }

    void realloc() {

        vector<T> temp;
        temp.resize(size);
        for(int i =0 ;i < size; i++){
            temp[i] =data[i];
        }

        data.resize(2 * size);

        for(int j = 0; j < size; j++ ){
            data[j] = temp[j];
        }
        size = 2 * size;
    }
};